package org.abc.fund.repository.factorRepository;

import org.abc.fund.entity.factorEntity.OperationType;
import org.abc.fund.entity.factorEntity.StyleFactorComponent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 风格因子组件Repository
 */
@Repository
public interface StyleFactorComponentRepository extends JpaRepository<StyleFactorComponent, Long> {

    /**
     * 根据风格因子ID查找组件列表
     */
    //List<StyleFactorComponent> findByStyleFactorIdOrderBySortOrderAsc(Long styleFactorId);

    /**
     * 根据输入因子ID查找组件列表
     */
//    List<StyleFactorComponent> findByInputFactorId(Long inputFactorId);

    /**
     * 根据风格因子ID和输入因子ID查找组件
     */
//    Optional<StyleFactorComponent> findByStyleFactorIdAndInputFactorId(Long styleFactorId, Long inputFactorId);
//
    /**
     * 根据风格因子ID删除所有组件
     */
    void deleteByStyleFactorId(Long styleFactorId);

    /**
     * 根据风格因子ID统计组件数量
     */
    long countByStyleFactorId(Long styleFactorId);

    /**
     * 根据操作类型查找组件
     */
    List<StyleFactorComponent> findByOperationType(OperationType operationType);

    /**
     * 根据权重范围查找组件
     */
    @Query("SELECT sfc FROM StyleFactorComponent sfc WHERE sfc.weight BETWEEN :minWeight AND :maxWeight")
    List<StyleFactorComponent> findByWeightBetween(@Param("minWeight") BigDecimal minWeight,
                                                  @Param("maxWeight") BigDecimal maxWeight);

    /**
     * 根据风格因子删除所有组件
     */
    void deleteByStyleFactor(org.abc.fund.entity.factorEntity.StyleFactor styleFactor);
}